<?php

namespace Core\Database;

use PDO;

class DatabaseConnection
{
    private $pdo;
    private $config;
    
    public function __construct($config)
    {
        $this->config = $config;
    }
    
    public function connect(): PDO
    {
        if ($this->pdo === null) {
            $dsn = "mysql:host={$this->config['host']};dbname={$this->config['database']};charset={$this->config['charset']}";
            $this->pdo = new PDO(
                $dsn,
                $this->config['username'],
                $this->config['password'],
                $this->config['options']
            );
        }
        
        return $this->pdo;
    }
    
    public function getPdo(): PDO
    {
        return $this->connect();
    }
}
